package com.zl.learning.swing;

import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;

public class TestTextArea {
    private JPanel panel1;
    private JTextArea textArea1;
    private JTextField textField1;
    private JButton sendBtn;

    public TestTextArea() {
        sendBtn.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                String msg = textField1.getText();
                textField1.setText("");
                textArea1.append(msg + "\n");
            }
        });
    }

    public static void main(String[] args) throws UnsupportedLookAndFeelException, InstantiationException, IllegalAccessException, ClassNotFoundException {
        UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
        new TestTextArea().init();
    }

    public void init() {
        JFrame frame = new JFrame();
        frame.add(panel1);
        frame.setSize(500, 300);
        frame.setLocation(300, 300);
        frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
        frame.addKeyListener(new KeyAdapter() {
            @Override
            public void keyTyped(KeyEvent e) {
                super.keyTyped(e);
            }
        });
        frame.setVisible(true);
    }
}
